﻿using System;
using System.Web.Mvc;

namespace nsadv.Statistic.Web.RenderHelpers
{
	using ViewModels;

	public static class MainSiteUrlRenderHelper
	{
		public static MvcHtmlString MainSiteUrl(this HtmlHelper html, string mainSiteRelativeUrl)
		{
			var model = html.ViewContext.ViewData.Model as BaseModel;
			if (model == null)
			{
				throw new ApplicationException("MainSiteUrlRenderHelper может быть использован только с BaseModel.");
			}

			Uri result;
			string resultUrl = string.Empty;
			if (Uri.TryCreate(new Uri( model.MainSiteUrl), mainSiteRelativeUrl, out result))
			{
				resultUrl = result.ToString();
			}

			return MvcHtmlString.Create(resultUrl);
		}
	}
}